﻿@{
    ViewBag.Title = "系统日志";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script type="text/javascript">
    $(document).ready(function () {
        GetTree();
        GetGrid("");
    });
    var ModuleId = "", ModuleName = "";
    //加载左边树
    function GetTree() {
        var itemtree = {
            onnodeclick: function (item) {
                ModuleId = item.id;            //ID
                ModuleName = item.text;        //名称
                $("#titleinfo").text(ModuleName);
                $("#gridTable").jqGrid('setGridParam', {
                    url: "@Url.Content("~/CommonModule/SysLog/GridPageListJson")?ModuleId=" + ModuleId, page: 1
                }).trigger('reloadGrid');
            },
            url: "@Url.Content("~/CommonModule/Module/TreeJson")"
        };
        $("#ItemsTree").treeview(itemtree);
    }
    //加载表格
    function GetGrid(ParameterJson) {
        $("#gridTable").jqGrid({
            url: "@Url.Content("~/CommonModule/SysLog/GridPageListJson")",
            datatype: "json",
            height: $(window).height() - 132,
            autowidth: true,
            colModel: [
                { label: "主键", name: "SysLogId", index: "SysLogId", hidden: true },
                {
                    label: "操作时间", name: "CreateDate", index: "CreateDate", width: 120,
                    formatter: function (value, options, rowObject) {
                        return formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                    }
                },
                { label: "操作模块", name: "ModuleId", index: "ModuleId", width: 100 },
                { label: "操作类型", name: "LogType", index: "LogType", width: 100, hidden: true },
                {
                    label: "操作类型名称", name: "LogTypeName", width: 65, align: "center",
                    formatter: function (value, options, rowObject) {
                        if (rowObject.LogType == '0') { return "登陆"; }
                        if (rowObject.LogType == '1') { return "新增"; }
                        if (rowObject.LogType == '2') { return "修改"; }
                        if (rowObject.LogType == '3') { return "删除"; }
                        if (rowObject.LogType == '4') { return "其他"; }
                        if (rowObject.LogType == '5') { return "访问"; }
                        if (rowObject.LogType == '6') { return "离开"; }
                        if (rowObject.LogType == '7') { return "查询"; }
                        if (rowObject.LogType == '8') { return "安全退出"; }
                    }
                },
                { label: "IP地址", name: "IPAddress", index: "IPAddress", width: 100 },
                { label: "操作用户", name: "CreateUserName", index: "CreateUserName", width: 80 },
                { label: "操作公司", name: "CompanyId", index: "CompanyId", width: 120 },
                { label: "操作部门", name: "DepartmentId", index: "DepartmentId", width: 80 },
                {
                    label: "操作状态", name: "Status", index: "Status", width: 50, align: "center",
                    formatter: function (value, options, rowObject) {
                        if (value == '1') {
                            return "<span style='color:blue'>成功</span>";
                        } else {
                            return "<span style='color:red'>失败</span>";
                        }
                    }
                },
                { label: "对象值", name: "ObjectId", index: "ObjectId", width: 260 },
                { label: "操作描述", name: "Remark", index: "Remark", width: 1000 },
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100, 500, 1000],
            pager: "#gridPager",
            sortname: 'CreateDate',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true
        });
        columnModelData("#gridTable");
    }
    //查询
    var QueryParamJson = "";
    function btn_query() {
        QueryDialog("/Utility/QueryPage", "QueryPage", "查询过滤", 770, 395, function (iframe) {
            top.frames[iframe].QueryClick(function (JsonData) {
                QueryParamJson = JsonData;
                $("#gridTable").jqGrid('setGridParam', {
                    url: "@Url.Content("~/CommonModule/SysLog/GridPageJson")?ParameterJson=" + escape(JsonData), page: 1
                }).trigger('reloadGrid');
            });
        });
    }
    //明细
    function btn_detail() {
        var SysLogId = GetJqGridRowValue("#gridTable", "SysLogId");
        var LogType = GetJqGridRowValue("#gridTable", "LogType");
        var LogTypeName = GetJqGridRowValue("#gridTable", "LogTypeName");
        if (IsChecked(SysLogId)) {
            var url = "/CommonModule/SysLog/Detail?SysLogId=" + SysLogId + '&LogType=' + LogType;
            Dialog(url, "Detail", '日志详细信息-【' + LogTypeName + '】', 850, 450);
        }
    }
    //清空数据
    function btn_broom() {
        var url = "/CommonModule/SysLog/RemoveLog";
        openDialog(url, "Form", "清空系统日志", 300, 80, function (iframe) {
            top.frames[iframe].AcceptClick();
        });
    }
    //导出Excel
    function btn_derive() {
        var GetToday = formatDate(CurrentTime(), 'yyyyMMdd');
        GetDeriveExcel("#grid_paging", "系统日志-" + GetToday);
    }
    //刷新表格
    function windowload() {
        $("#gridTable").trigger("reloadGrid"); //重新载入  
    }
</script>
<div id="layout" class="layout">
    <!--左边-->
    <div class="layoutPanel layout-west">
        <div class="btnbartitle">
            <div>
                导航目录
            </div>
        </div>
        <div class="ScrollBar" id="ItemsTree"></div>
    </div>
    <!--中间-->
    <div class="layoutPanel layout-center">
        <div class="btnbartitle">
            <div>
                系统日志 - <span id="titleinfo">所有日志</span>
            </div>
        </div>
        <div class="tools_bar" style="border-top: none; margin-bottom: 0px;">
            <div class="PartialButton">
                @Html.Partial("_PartialButton")
            </div>
        </div>
        <table id="gridTable"></table>
        <div id="gridPager"></div>
    </div>
</div>
